package controllers.administrator;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import services.AuctionService;
import services.BidService;
import services.CommentService;
import services.CustomerService;
import services.GalleryService;
import services.PaintingService;
import controllers.AbstractController;
import domain.Auction;
import domain.Bid;
import domain.Comment;
import domain.Customer;
import domain.Dashboard;
import domain.Gallery;
import domain.Painting;

@Controller
@RequestMapping("/dashboard/administrator")
public class DashboardAdministratorController extends AbstractController {
	@Autowired
	private BidService bidService;

	@Autowired
	private CustomerService customerService;

	@Autowired
	private GalleryService galleryService;

	@Autowired
	private AuctionService auctionService;

	@Autowired
	private PaintingService paintingService;

	@Autowired
	private CommentService commentService;

	public DashboardAdministratorController() {
		super();
	}

	// Listing methods
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public ModelAndView list() {
		ModelAndView result;
		Dashboard dashboard;
		Collection<Bid> highestBid;
		Collection<Customer> custMorePainting;
		Collection<Gallery> mostExpensiveGallery;
		Collection<Auction> auctMoreBids;
		Collection<Customer> customersMoreComments;
		Collection<Painting> paintingsMoreComments;
		Collection<Comment> commentsMoreResponses;

		dashboard = new Dashboard();
		highestBid = bidService.findByHigeshtBid();
		custMorePainting = customerService.findByMorePaintings();
		mostExpensiveGallery = galleryService.findByMoreExpensive();
		auctMoreBids = auctionService.findByMoreBids();
		customersMoreComments = customerService.findByMoreComments();
		paintingsMoreComments = paintingService.findByMoreComments();
		commentsMoreResponses = commentService.findByMoreResponses();

		dashboard.setCommentMoreResponses(commentsMoreResponses);
		dashboard.setCustomerMorePaiting(custMorePainting);
		dashboard.setHighestBid(highestBid);
		dashboard.setMostExpensiveGallery(mostExpensiveGallery);
		dashboard.setAuctionMoreBids(auctMoreBids);
		dashboard.setPaintingsMoreComments(paintingsMoreComments);
		dashboard.setCustomersMoreComments(customersMoreComments);

		result = new ModelAndView("dashboard/list");
		result.addObject("requestURI", "dashboard/administrator/list.do");
		result.addObject("dashboard", dashboard);
		result.addObject("backURI", "/welcome/index.do");
		return result;
	}
}